<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<% 
//String g_id=request.getParameter("group_id"); 
String g_name=request.getParameter("group_name");
String g_project=request.getParameter("project");
String pro=null;
%>
<%
//insert into group1(group1.group_name,group1.project_id) values ("gamma",'5');
//String query="insert into group1 values('"+g_id+"','"+g_name+"')";
String query="select project.project_id from project where project.name='"+g_project+"'";
Connection db_conn = null;
Statement statement = null;
PreparedStatement pstmt;
ResultSet rs;
try{
Class.forName("com.mysql.jdbc.Driver");
String url= "jdbc:mysql://localhost:3306/db";
db_conn = DriverManager.getConnection( url,"root", "root" );
statement = db_conn.createStatement();
rs=statement.executeQuery(query);
while(rs.next())
    {
        pro=rs.getString("project_id");
    }
    //statement.executeUpdate(query);

db_conn.close();
} catch(SQLException e){
//e.printStackTrace();
out.println("Group already exists");
//out.println(e);
} catch(ClassNotFoundException e){
    out.println("Group already exists");

//e.printStackTrace();
//out.println(e);
}
%>         



<%
out.println(pro);
String query1="insert into group1(group1.group_name,group1.project_id) values('"+g_name+"','"+pro+"')";
Connection db_conn1 = null;
Statement statement1 = null;
PreparedStatement pstmt1;
ResultSet rs1;
try{
Class.forName("com.mysql.jdbc.Driver");
String url= "jdbc:mysql://localhost:3306/db";
db_conn1 = DriverManager.getConnection( url,"root", "root" );
statement1 = db_conn1.createStatement();
statement1.executeUpdate(query1);
db_conn1.close();
} catch(SQLException e){
e.printStackTrace();
out.println("sql not found");
out.println(e);
} catch(ClassNotFoundException e){
e.printStackTrace();
out.println(e);
}
%>        



